package bf.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ibatis.sqlmap.client.SqlMapClient;

public class FactoryDao {
	private SqlMapClient sqlMapClient;
	public FactoryDao(SqlMapClient sqlMapClient){
		this.sqlMapClient = sqlMapClient;
	}
	public int getLotListIdByToday() throws SQLException {
		int i=0;
		if(sqlMapClient.queryForObject("factory.getLotListIdByToday")!=null){
			i=(Integer) sqlMapClient.queryForObject("factory.getLotListIdByToday");
		}
		return i;
	}
	public void setLotList() throws SQLException {
		sqlMapClient.insert("factory.setLotList");
	}
	public int setLotNgetLotId(LotVO lvo) throws SQLException {
		return (Integer) sqlMapClient.insert("factory.setLotNgetLotId",lvo);
	}
	public int setOp1(OperationVO ovo) throws SQLException {
		return (Integer) sqlMapClient.insert("factory.setOp1",ovo);
	}
	public int setOp2(OperationVO ovo) throws SQLException {
		return (Integer) sqlMapClient.insert("factory.setOp2",ovo);
	}
	public int setOp3(OperationVO ovo) throws SQLException {
		return (Integer) sqlMapClient.insert("factory.setOp3",ovo);
	}
	public void setOp1End(int opId) throws SQLException {
		sqlMapClient.update("factory.setOp1End",opId);
	}
	public void setOp2End(int opId) throws SQLException {
		sqlMapClient.update("factory.setOp2End",opId);
	}
	public void setOp3End(int opId) throws SQLException {
		sqlMapClient.update("factory.setOp3End",opId);
	}
	public List<Integer> getlotOPHp() throws SQLException {
		return sqlMapClient.queryForList("factory.getlotOPHp");
	}
	public int op1FailCount(int lotId) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("factory.op1FailCount",lotId);
	}
	public int op2FailCount(int lotId) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("factory.op2FailCount",lotId);
	}
	public int op3FailCount(int lotId) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("factory.op3FailCount",lotId);
	}
	public int getLotOk(int lotId) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("factory.getLotOk",lotId);
	}
	public void setLot(LotVO lvo) throws SQLException {
		sqlMapClient.update("factory.setLot",lvo);
	}
	public MemberVO login(MemberVO mvo) throws SQLException{
		return (MemberVO) sqlMapClient.queryForObject("factory.login", mvo);
	}
	// machine정보 모두 가져오는 Dao
	public List getMachineInfo() throws SQLException{
		return (List) sqlMapClient.queryForList("factory.getMachineInfo");
	}
	// machine 추가하는 Dao
	public void updateMachine(String mc_id) throws SQLException{
		sqlMapClient.update("factory.updateMachine", mc_id);
	}
	 // 1공정 현황 정보 가져오기
	 public List<OperationVO> getOperation1Info() throws SQLException{
		 return sqlMapClient.queryForList("factory.getOperation1Info");
	 }
	// 2공정 현황 정보 가져오기
	 public List<OperationVO> getOperation2Info() throws SQLException{
		 return sqlMapClient.queryForList("factory.getOperation2Info");
	 }
	// 3공정 현황 정보 가져오기
	 public List<OperationVO> getOperation3Info() throws SQLException{
		 return sqlMapClient.queryForList("factory.getOperation3Info");
	 }
	public void machineAfterLot(int lotOP1Hp, int lotOP2Hp, int lotOP3Hp) throws SQLException {
		sqlMapClient.update("factory.lotOP1HpmachineAfterLot",lotOP1Hp);
		sqlMapClient.update("factory.lotOP2HpmachineAfterLot",lotOP2Hp);
		sqlMapClient.update("factory.lotOP3HpmachineAfterLot",lotOP3Hp);
	}
	// history에 정보 담기
	public void setHistory(HistoryVO hvo) throws SQLException{
		sqlMapClient.insert("factory.setHistory", hvo);
	}
	// history에 담을 his_day_op1_fail 가져오기
	public double getHis_day_op1_fail(int lot_list_id) throws SQLException{
		return (Double) sqlMapClient.queryForObject("factory.getHis_day_op1_fail", lot_list_id);
	}
	// history에 담을 his_day_op2_fail 가져오기
	public double getHis_day_op2_fail(int lot_list_id) throws SQLException{
		return (Double) sqlMapClient.queryForObject("factory.getHis_day_op2_fail", lot_list_id);
	}
	// history에 담을 his_day_op3_fail 가져오기
	public double getHis_day_op3_fail(int lot_list_id) throws SQLException{
		return (Double) sqlMapClient.queryForObject("factory.getHis_day_op3_fail", lot_list_id);
	}
	// history에 담을 his_start
	public String getHis_start(int lot_list_id) throws SQLException{
		return (String) sqlMapClient.queryForObject("factory.getHis_start", lot_list_id);
	}
	// history에 담을 his_end
	public String getHis_end(int lot_list_id) throws SQLException{
		return (String) sqlMapClient.queryForObject("factory.getHis_end", lot_list_id);
	}
	// history에 담을 his_day_ok
	public int getHis_day_ok(int lot_list_id) throws SQLException{
		return (Integer) sqlMapClient.queryForObject("factory.getHis_day_ok", lot_list_id);
	}
	// history에 담을 his_day_fail
	public double getHis_day_fail(int lot_list_id) throws SQLException{
		return (Double) sqlMapClient.queryForObject("factory.getHis_day_fail", lot_list_id);
	}
	// history에 담을 his_op1_hp
	public int getHis_op1_hp(int lot_list_id) throws SQLException{
		return (Integer) sqlMapClient.queryForObject("factory.getHis_op1_hp", lot_list_id);
	}
	// history에 담을 his_op2_hp
	public int getHis_op2_hp(int lot_list_id) throws SQLException{
		return (Integer) sqlMapClient.queryForObject("factory.getHis_op2_hp", lot_list_id);
	}
	// history에 담을 his_op3_hp
	public int getHis_op3_hp(int lot_list_id) throws SQLException{
		return (Integer) sqlMapClient.queryForObject("factory.getHis_op3_hp", lot_list_id);
	}
	// 전 랏 기준의 불량품갯수
	public int getBeforeLotFailCount() throws SQLException{
		int i=0;
		if(sqlMapClient.queryForObject("factory.getBeforeLotFailCount")!=null){
			i=(Integer)sqlMapClient.queryForObject("factory.getBeforeLotFailCount");
		}
		return i;
	}
	// history에 담을 his_lot_total
	public int getHis_lot_total(int lot_list_id) throws SQLException{
		return (Integer) sqlMapClient.queryForObject("factory.getHis_lot_total", lot_list_id);
	}
	// history에 담을 lot_list_id
	public int getLot_list_id() throws SQLException{
		return (Integer) sqlMapClient.queryForObject("factory.getLot_list_id");
	}
	// 당일 lot_list_id 구하는...
	public int getToday_lot_list_id() throws SQLException{
		return (Integer) sqlMapClient.queryForObject("factory.getToday_lot_list_id");
	}
	// 푸우꺼 제우가 넣음
	public ArrayList getRefreshInfoDiv1() throws SQLException{
		return (ArrayList) sqlMapClient.queryForList("factory.getRefreshInfoDiv1");
	}
	public ArrayList getRefreshInfoDiv2() throws SQLException{
		return (ArrayList) sqlMapClient.queryForList("factory.getRefreshInfoDiv2");
	}
	public ArrayList getRefreshInfoDiv3() throws SQLException{
		return (ArrayList) sqlMapClient.queryForList("factory.getRefreshInfoDiv3");
	}
	public ArrayList getRefreshInfoDiv4() throws SQLException{
		return (ArrayList) sqlMapClient.queryForList("factory.getRefreshInfoDiv4");
	}
	// require insert
	public void setRequire(RequireVO rvo) throws SQLException{
		sqlMapClient.insert("factory.setRequire", rvo);
	}
	// stock insert
	public void setStock(StockVO svo) throws SQLException{
		sqlMapClient.insert("factory.setStock", svo);
	}
	// 전달 stock의 st_mount 가져오기
	public int getSt_mount() throws SQLException{
		int i=0;
		if(sqlMapClient.queryForObject("factory.getSt_mount")!=null){
			i=(Integer)sqlMapClient.queryForObject("factory.getSt_mount");
		}
		return i;
	}
	// require 현황 가져오기
	public ArrayList<RequireVO> getBf_require() throws SQLException{
		return (ArrayList<RequireVO>) sqlMapClient.queryForList("factory.getBf_require");
	}
	// stock 현황 가져오기
	public ArrayList<StockVO> getBf_stock() throws SQLException{
		return (ArrayList<StockVO>) sqlMapClient.queryForList("factory.getBf_stock");
	}
	//랏 현황 페이지 이동시 뿌려줄 랏 현황
	public List<LotVO> elementLotState() throws SQLException {
		System.out.println(sqlMapClient.queryForList("factory.elementLotState"));
		return sqlMapClient.queryForList("factory.elementLotState");
	}
	// history 정보 가져오기
	public ArrayList<HistoryVO> getBf_history() throws SQLException{
		return (ArrayList<HistoryVO>) sqlMapClient.queryForList("factory.getBf_history");
	}
}